#ifndef _DS1302_H_
#define _DS1302_H_

typedef struct ds_time{

	uint16_t channel;
	uint16_t seconds;
	uint16_t minutes;
	uint16_t hours;
	uint16_t dayofweek;
	uint16_t dayofmonth;
	uint16_t month;
	uint16_t year;
	uint16_t century;

}DS_TIME;

extern DS_TIME my_time;

extern void DS1302_Init(void);
extern uint16_t DS1302_ReadReg(uint16_t addr);
extern void DS1302_WriteReg(uint16_t addr, uint16_t data);
extern void DS1302_SetTime(uint16_t year, 
	uint16_t month, 
	uint16_t dayofmonth, 
	uint16_t hours, 
	uint16_t minutes, 
	uint16_t seconds);
extern void DS1302_ReadTime(DS_TIME *my_time);

#define DS1302_RST  GPIO_PIN_4  // PD4
#define DS1302_CLK  GPIO_PIN_1  // PE1
#define DS1302_DAT  GPIO_PIN_2  // PE2

#define DS1302_ADDR_SECONDS  0x80
#define DS1302_ADDR_MINUTES  0x82
#define DS1302_ADDR_HOURS    0x84
#define DS1302_ADDR_DAYoM    0x86  // day of month
#define DS1302_ADDR_MONTH    0x88
#define DS1302_ADDR_DAYoW    0x8A  // day of week
#define DS1302_ADDR_YEAR     0x8C
#define DS1302_ADDR_CTRL     0x8E  // control
#define DS1302_ADDR_CHARGE   0x90
#define DS1302_ADDR_CLK      0xBE


#endif
